/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.example;

/**
 *
 * @author Shameera
 */
    import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
public class FolderViwer {

    public FolderViwer(String url) {
        File File = new File(url);
        iterate(File);
    }




	public void iterate(File folder) {
		ArrayList<File> folders = getFolders(folder);
		for (int i = 0; i < folders.size(); i++) {
			System.out.println(folders.get(i));
                        // we add the subfolders of the current folder to the main FOLDERS array list
			folders.addAll(getFolders(folders.get(i)));
                        // then we remove the current folder, so that we dont read it twice
			folders.remove(i);
		}
	}

	private ArrayList<File> getFolders(File folder) {
		ArrayList<File> listAr = new ArrayList<File>();
                // uses FileFilter to just pull out directories, then puts in an array
		File[] list = folder.listFiles(new FileFilter() {

			public boolean accept(File file) {
				if (file.isDirectory())
					return true;
				return false;
			}
		});

                // puts all the items from the array in an arraylist
		for (int i = 0; i < list.length; i++)
			listAr.add(list[i]);


		return listAr;
	}
//
//	public void showfolders(){
//
//		FolderViwer myFolderList = new FolderViwer();
//		File File = new File("/");
//		myFolderList.iterate(File);
//
//	}

}
